<template>
  <el-dialog
    title="课件列表"
    :close-on-click-modal="false"
    :visible.sync="visible"
    class="JADP-dialog JADP-dialog_center"
    lock-scroll
    width="70%"
    append-to-body
  >
    <JADP-table
      v-loading="loading"
      :data="list"
      @sort-change="sortChange"
      highlight-current-row
      @current-change="handleCurrentChange"
      :row-style="{ cursor: 'pointer' }"
      height="400"
    >
      <el-table-column
        prop="crmName"
        label="课程名称"
        align="left"
        show-overflow-tooltip
      />
      <el-table-column
        prop="name"
        label="课件名称"
        align="left"
        show-overflow-tooltip
      />
      <el-table-column v-show="false" label="时长" align="center">
        <template v-slot="{ row }">
          {{ row.fen ? row.fen + "分" + row.miao + "秒" : 0 }}
        </template>
      </el-table-column>
      <el-table-column
        prop="teacher"
        label="主讲老师"
        align="center"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column prop="coursewaretime" label="学时" align="center">
      </el-table-column>
    </JADP-table>

    <pagination
      :total="total"
      :page.sync="listQuery.currentPage"
      :limit.sync="listQuery.pageSize"
      @pagination="initData(true)"
    />

    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="dataFormSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import request from "@/utils/request";
export default {
  name: "clazztable",
  data() {
    return {
      visible: false,
      loading: false,
      total: 0,
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: ""
      },
      list: [],
      currentRow: null,
      classIdValue: ""
    };
  },
  created() {},
  methods: {
    initData(bol, classId) {
      console.log(classId, "classId");
      this.visible = true;
      this.loading = true;
      if (bol) {
        if (this.classIdValue) {
        } else {
          this.classIdValue = classId || 0;
          this.listQuery.currentPage = 1;
        }
      } else {
        this.classIdValue = classId || 0;
        this.listQuery.currentPage = 1;
      }
      let _query = {
        ...this.listQuery,
        classId: this.classIdValue,
        organizeId:this.$store.getters.organizeId
      };

      request({
        url: `/api/courseware/Xy_ks_courseware/getCoursewarList`,
        method: "get",
        data: _query
      }).then(res => {
        this.list = res.data.list;
        this.total = res.data.pagination.total;
        this.loading = false;
      });
    },

    handleCurrentChange(val) {
      console.log(val, 111111);
      this.currentRow = val;
    },
    sortChange({ column, prop, order }) {
      this.listQuery.sort = order == "ascending" ? "asc" : "desc";
      this.listQuery.sidx = !order ? "" : prop;
      this.initData(true);
    },

    dataFormSubmit() {
      if (this.currentRow) {
        this.$emit("currentRow", this.currentRow);
        this.visible = false;
      } else {
        this.$message.warning("请至少选择一个班级");
      }
    }
  }
};
</script>
<style scoped lang="scss"></style>
